﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SortAndDatastruct {
    /// <summary>
    /// 排序辅助类
    /// </summary>
    class SortHelper {
        internal static int[] MillArray;
        internal static int[] LittleArray = new int[] { 8, 5, 4, 1, 3, 2, 6, 7, 0, 9, 10, 11, 23, 10, 107, 111, 156, 1278, 1023, 78, 1113 };
        static SortHelper() {
            MillArray = new int[1000000];
            System.Random ran = new System.Random();
            for (int i = 0; i < 1000000; ++i) {
                MillArray[i] = ran.Next();
            }
        }

        /// <summary>
        /// 置换数组中的元素
        /// </summary>
        /// <param name="A">数据A</param>
        /// <param name="B">数据B</param>
        internal static void SWAP(ref int A, ref int B) {
            if (A.Equals(B)) return;
            int temp = A; A = B; B = temp;
        }
        /// <summary>
        /// 同时获取最大值与最小值
        /// </summary>
        /// <param name="Array">数据源</param>
        /// <param name="min">最小值</param>
        /// <param name="max">最大值</param>
        internal static void GetMaxAndMin(ref int[] Array, out int min, out int max) {
            if (Array == null || Array.Length < 1) { min = max = 0; return; }
            if (Array.Length == 1) {
                max = min = Array[0];
            }
            max = min = Array[0];
            for (int i = 0; i < Array.Length - 1; ++i) {
                if (Array[i] < Array[i + 1]) {
                    if (Array[i + 1] > max) {
                        max = Array[i + 1];
                    }
                    if (min > Array[i]) {
                        min = Array[i];
                    }
                } else {
                    if (Array[i] > max) {
                        max = Array[i];
                    }
                    if (min > Array[i + 1]) {
                        min = Array[i + 1];
                    }
                }
            }
        }
    }
}
